﻿// WhiteCutDlg.cpp: 实现文件
//

#include "pch.h"
#include "ProjectAA.h"
#include "WhiteCutDlg.h"
#include "afxdialogex.h"


// CWhiteCutDlg 对话框

IMPLEMENT_DYNAMIC(CWhiteCutDlg, CDialogEx)

CWhiteCutDlg::CWhiteCutDlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DIALOG_WHITECUT, pParent)
	, SearchX(0)
	, SearchY(0)
	, SearchW(0)
	, SearchH(0)
	, CircleX(0)
	, CircleY(0)
	, CircleR(0)
	, CutFlag(FALSE)
{

}

CWhiteCutDlg::~CWhiteCutDlg()
{
}

void CWhiteCutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_COMBO1, m_comboCutMode);
	DDX_Text(pDX, IDC_EDIT1, SearchX);
	DDX_Text(pDX, IDC_EDIT2, SearchY);
	DDX_Text(pDX, IDC_EDIT3, SearchW);
	DDX_Text(pDX, IDC_EDIT4, SearchH);
	DDX_Text(pDX, IDC_EDIT6, CircleX);
	DDX_Text(pDX, IDC_EDIT7, CircleY);
	DDX_Text(pDX, IDC_EDIT8, CircleR);
	DDX_Check(pDX, IDC_CHECK5, CutFlag);
}


BEGIN_MESSAGE_MAP(CWhiteCutDlg, CDialogEx)
	ON_BN_CLICKED(IDC_BUTTON1, &CWhiteCutDlg::OnBnClickedButton1)
END_MESSAGE_MAP()


// CWhiteCutDlg 消息处理程序


BOOL CWhiteCutDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	ReadConfigIni();

	m_comboCutMode.ResetContent();
	m_comboCutMode.AddString(L"0: 矩形");
	m_comboCutMode.AddString(L"1: 圆形");
	m_comboCutMode.SetCurSel(gSystemMgr.CutImgMode);



	return TRUE;
}


void CWhiteCutDlg::OnCancel()
{
	// TODO: 在此添加专用代码和/或调用基类

	CDialogEx::OnCancel();
}

void CWhiteCutDlg::ReadConfigIni()
{
	SearchX = gSystemMgr.m_nCutSearchX;
	SearchY = gSystemMgr.m_nCutSearchY;
	SearchW = gSystemMgr.m_nCutSearchW;
	SearchH = gSystemMgr.m_nCutSearchH;
	CircleX = gSystemMgr.m_nCutSearchX2;
	CircleY = gSystemMgr.m_nCutSearchY2;
	CircleR = gSystemMgr.m_nCutCircleR;
	CutFlag = gSystemMgr.CutFlag;
	UpdateData(FALSE);
}

void CWhiteCutDlg::SaveEditValueToConfig()
{
	UpdateData(TRUE);

	gSystemMgr.m_nCutSearchX = SearchX;
	gSystemMgr.m_nCutSearchY = SearchY;
	gSystemMgr.m_nCutSearchW = SearchW;
	gSystemMgr.m_nCutSearchH = SearchH;
	gSystemMgr.m_nCutSearchX2 = CircleX;
	gSystemMgr.m_nCutSearchY2 = CircleY;
	gSystemMgr.m_nCutCircleR = CircleR;
	gSystemMgr.CutImgMode = m_comboCutMode.GetCurSel();

	gSystemMgr.CutFlag = CutFlag;

	CString cstr;
	cstr.Format(L"%d", gSystemMgr.CutFlag); gSystemMgr.m_cCutConfigIni.SaveConfigIni(L"ImageCut", L"CutFlag", cstr);

	cstr.Format(L"%d", gSystemMgr.m_nCutSearchX); gSystemMgr.m_cCutConfigIni.SaveConfigIni(L"ImageCut", L"m_nCutSearchX", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nCutSearchY); gSystemMgr.m_cCutConfigIni.SaveConfigIni(L"ImageCut", L"m_nCutSearchY", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nCutSearchW); gSystemMgr.m_cCutConfigIni.SaveConfigIni(L"ImageCut", L"m_nCutSearchW", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nCutSearchH); gSystemMgr.m_cCutConfigIni.SaveConfigIni(L"ImageCut", L"m_nCutSearchH", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nCutSearchX2); gSystemMgr.m_cCutConfigIni.SaveConfigIni(L"ImageCut", L"m_nCutSearchX2", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nCutSearchY2); gSystemMgr.m_cCutConfigIni.SaveConfigIni(L"ImageCut", L"m_nCutSearchY2", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nCutCircleR); gSystemMgr.m_cCutConfigIni.SaveConfigIni(L"ImageCut", L"m_nCutCircleR", cstr);

	cstr.Format(L"%d", gSystemMgr.CutImgMode); gSystemMgr.m_cCutConfigIni.SaveConfigIni(L"ImageCut", L"CutImgMode", cstr);

}


void CWhiteCutDlg::OnBnClickedButton1()
{
	SaveEditValueToConfig();
}
